<?php
/*
服务器数据通信接口
*/
require_once("../../control/base.php");
//查询数据库
$staff = query("staff"," stid = '$post[stid]' ");
$job = query("job"," id = '$staff[jobId]' ");
$role = query("role"," id = '$job[roleId]' ");
$power = json_decode($role['power'],true);
$buyCarAllot = query("buyCarAllot"," id = '$post[buyCarAllotId]' ");
$projectPage = query("projectPage"," id = '$post[projectPageId]' ");
$project = query("project"," id = '$projectPage[projectId]' ");
//判断
if(empty($post['stid'])){
	$warn = "员工ID号为空";
}elseif(empty($staff['stid'])){
	$warn = "未找到此员工";
}elseif($staff['pas'] != $post['pas']){
	$warn = "登录密码有误";
}elseif(!in_array("edit",$power["orderAllot"])){
	$warn = "您没有编辑项目源代码的权限";
}elseif(empty($post['projectPageId'])){
	$warn = "代码文件ID号为空";
}elseif(empty($projectPage['id'])){
	$warn = "未找到此页面";
}elseif(empty($post['buyCarAllotId'])){
	$warn = "任务ID为空";
}elseif(empty($buyCarAllot['id'])){
	$warn = "未找到此任务";
}elseif($buyCarAllot['stid'] != $staff['stid']){
	$warn = "这不是您的任务";
}elseif($buyCarAllot['projectId'] != $projectPage['projectId']){
	$warn = "此代码文件的项目与此任务项目不一致";
}elseif($projectPage['auditing'] != "已通过"){
	$warn = "本代码文件还未通过审核";
}elseif(empty($project['fileName'])){
	$warn = "项目文件夹为空";
}elseif(empty($projectPage['url'])){
	$warn = "代码文件根目录路径为空";
}elseif($post['type'] == "getCode"){
	$warn = 2;
	$array['projectPageName'] = $projectPage['name'];
}elseif($post['type'] == "codeEdit"){
	if(empty($post['codeText'])){
		$warn = "代码不能为空";
	}elseif($buyCarAllot['editPower'] != "编辑"){
		$warn = "您的本项目任务没有编辑权限";
	}elseif($projectPage['jurisdiction'] != "编辑"){
		$warn = "本代码文件处于非编辑状态";
	}elseif($projectPage['powerId'] != $staff['stid']){
		$warn = "您还没有获取编辑权";
	}else{
		$warn = 2;
	}
}else{
	$warn = "未知类型";
}
if($warn == 2){
	$array['url'] = $project['fileName']."/".$projectPage['url'];
}else{
	$array['warn'] = $warn;
}
//输出
echo arrayToXml($array);
?>